package main

import "fmt"

// 接口的嵌套
type animal interface {
	mover
	eater
}
type mover interface {
	move()
}
type eater interface {
	eat(string)
}

type cat struct {
	name string
}

// 实现了mover接口
func (c cat) move() {
	fmt.Println("走猫步。。")
}

// 实现了eater接口
// 使用指针接收者
func (c *cat) eat(st string) {
	fmt.Printf("吃%s\n", st)
}

type chicken struct {
	name string
}

// 使用的值类型接收者

func (c chicken) eat(st string) {
	fmt.Printf("吃%s\n", st)
}
func (c chicken) move() {
	fmt.Println("鸡动了。。")
}

func main() {
	c1 := cat{"小猫"}
	fmt.Printf("%T %v\n", c1, c1)

	cken1 := &chicken{"小鸡"}
	fmt.Printf("%T %v\n", cken1, cken1)

	var a animal // a = nil
	fmt.Printf("%T\n", a)

	a = &c1 //传递指针
	fmt.Printf("%T\n", a)
	a.eat("鱼儿")
	a.move()

	a = cken1
	fmt.Printf("%T\n", a)
	a.eat("虫")
	a.move()

	c1.eat("小黄鱼")
	c1.move()
	fmt.Println(c1.name)

	cken1.eat("小虫子")
	cken1.move()
	fmt.Println(cken1.name)
}
